
import CryptoJS from 'crypto-js'
 
//加密
// export function encrypt(word, keyStr){ 
export function encrypt(keyStr,word){
	var key  = CryptoJS.enc.Utf8.parse(keyStr);
	var encrypted = CryptoJS.AES.encrypt(word, key, {mode:CryptoJS.mode.CBC,padding: CryptoJS.pad.Pkcs7,iv: key});
	let str = encrypted.toString();
	console.log(str);
	str = str.replace(/\+/g,"%2B");
	// str = encodeURI(str)
	return str;
}
 
//解密
// export function decrypt(word, keyStr){  
export function decrypt(keyStr,word){
	var key  = CryptoJS.enc.Utf8.parse(keyStr);//Latin1 w8m31+Yy/Nw6thPsMpO5fg==
	//删除转行
	word = word.replace(/\n/g,"");
	word = word.replace(/\s/g,"");
	var decrypt = CryptoJS.AES.decrypt(word, key, {mode:CryptoJS.mode.CBC,padding: CryptoJS.pad.Pkcs7,iv: key,});
	return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}